﻿using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
using FrontRoomCheck.Model;
using FrontRoomCheck.Properties;
using FrontRoomCheck.Utiltiy;
using YJKFamilyLibDataManager;

namespace FrontRoomCheck.FireAreOutLineAppend
{
	public static class BaseManger
	{
		public static List<AdapteDoorResultPakcer> GetCheckResults(List<ViewPlan> inputValues)
		{
			List<AdapteDoorResultPakcer> list = new List<AdapteDoorResultPakcer>();
			foreach (ViewPlan useViewPlan in inputValues)
			{
				List<Def_Sel> onOutLineWinDoorWall = BaseChecker.GetOnOutLineWinDoorWall(useViewPlan);
				foreach (Def_Sel useOutLinePacker in onOutLineWinDoorWall)
				{
					list.Add(new AdapteDoorResultPakcer(useOutLinePacker, StaticRescource.m_SelectLevels));
				}
			}
			return list;
		}

		public static bool MakeCloseWalls(List<ViewPlan> inputValue)
		{
			ViewPlan activeView = StaticRescource.CmdData.Application.ActiveUIDocument.ActiveView as ViewPlan;
			bool flag = true;
			foreach (ViewPlan inputValue2 in inputValue)
			{
				flag = (flag && BaseManger.MakeCloseWalls(inputValue2));
			}
			StaticRescource.CmdData.Application.ActiveUIDocument.ActiveView = activeView;
			return flag;
		}

		internal static bool MakeCloseWalls(ViewPlan inputValue)
		{
			return BaseReplacer.CloseFireAreaWalls(inputValue);
		}

		public static Dictionary<string, List<string>> GetFamilyNames(Document inputDocument = null, bool ifInFamilyLib = false)
		{
			Dictionary<string, List<string>> dictionary = new Dictionary<string, List<string>>();
			List<string> list = new List<string>
			{
				Resources.Str_FamilyDbKindName_FireDoor,
				Resources.Str_FamilyDbKindName_FireRoolDoor,
				Resources.Str_FamilyDbKindName_FireWindow
			};
			foreach (string key in list)
			{
				dictionary.Add(key, new List<string>());
			}
			if (inputDocument != null && !ifInFamilyLib)
			{
				using (List<string>.Enumerator enumerator2 = list.GetEnumerator())
				{
					while (enumerator2.MoveNext())
					{
						string text = enumerator2.Current;
						dictionary[text].AddRange(BaseManger.GetValidFamilyNameFromtDocument(inputDocument, text));
					}
					return dictionary;
				}
			}
			if (ifInFamilyLib)
			{
				foreach (string text2 in list)
				{
					List<DbFamily> familysFromFamilyLid = Utility.GetFamilysFromFamilyLid(text2);
					List<string> collection = (from e in familysFromFamilyLid
					select e.Name).ToList<string>();
					dictionary[text2].AddRange(collection);
				}
			}
			return dictionary;
		}

		private static List<string> GetValidFamilyNameFromtDocument(Document inputDocument, string useKindName)
		{
			List<string> result = new List<string>();
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(inputDocument);
			if (useKindName.Equals(Resources.Str_FamilyDbKindName_FireDoor))
			{
				List<FamilyInstance> source = filteredElementCollector.OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_Doors).Cast<FamilyInstance>().Where(new Func<FamilyInstance, bool>(Utility.IsValidFireDoors)).ToList<FamilyInstance>();
				result = (from e in source
				select e.Symbol.Family.Name).Distinct<string>().ToList<string>();
			}
			else if (useKindName.Equals(Resources.Str_FamilyDbKindName_FireRoolDoor))
			{
				List<FamilyInstance> source2 = filteredElementCollector.OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_Doors).Cast<FamilyInstance>().Where(new Func<FamilyInstance, bool>(Utility.IsValidFireDoorRollings)).ToList<FamilyInstance>();
				result = (from e in source2
				select e.Symbol.Family.Name).Distinct<string>().ToList<string>();
			}
			else if (useKindName.Equals(Resources.Str_FamilyDbKindName_FireWindow))
			{
				List<FamilyInstance> source3 = filteredElementCollector.OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_Windows).Cast<FamilyInstance>().Where(new Func<FamilyInstance, bool>(Utility.IsValidFireWindows)).ToList<FamilyInstance>();
				result = (from e in source3
				select e.Symbol.Family.Name).Distinct<string>().ToList<string>();
			}
			return result;
		}
	}
}
